using System;
using System.Collections.Generic;
using System.Text;
using JobShopModel.Model.JobLvl;
using JobShopModel.Model.FactoryLvl;

//TODO Doculentation
namespace JobShopModel.Model.Station
{
    /// <summary>
    /// The station at which jobs are created and to which they return before exiting
    /// </summary>
    class StationIO : IStations
    {


        private Time operationTime;
        private Time iddleTime;
        private Time blockedTime;

        private StationsStates states;
        private StationsName name;

        /// <summary>
        /// Default COnstructor
        /// Do not use the properties to set all the value to default (ie at 0)
        /// </summary>
        public StationIO()
        {
            this.operationTime = new Time();
            this.iddleTime = new Time();
            this.blockedTime = new Time();
            this.states = StationsStates.AVAILABLE;
            this.name = StationsName.IOSTATION;
        }

        public Time TotalOperationTime
        {
            get
            {
                return operationTime;
            }
        }

        public Time TotalIddleTime
        {
            get
            {
                return iddleTime;
            }
        }

        public Time TotalBlockedTime
        {
            get
            {
                return blockedTime;
            }
        }

        /// <summary>
        /// State Property
        /// Check if the change of state is valid.
        /// If not, throw an Exception
        /// 
        /// </summary>
        public StationsStates State
        {
            get
            {
                return states;
            }
            set
            {
                if (this.states == StationsStates.BUSY && value == StationsStates.AVAILABLE)
                {
                    this.states = value;
                }
                else if (this.states == StationsStates.AVAILABLE && value == StationsStates.BUSY)
                {
                    this.states = value;
                }
                else
                {
                    throw new Exception("Illegal Operation: you are not suppose to change the state to an iddentical state");
                }
            }
        }

        public Time PerformOperation(Operation op)
        {
            return op.ServiceTime;
        }

        public override string ToString()
        {
            return this.name.ToString();
        }

        
        public StationsName Name
        {
            get { return name; }
        }

    }
}
